package com.gdk.ksoft.assembly.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * Created by hel on 2014-11-28.
 * 消息提示框
 */
public class MessageBox extends Dialog {

    /**
     * 确定按钮ID
     */
    public static final int ID_DIALOG_BUTTON_OK = R.id.dialog_messagebox_txtOk;
    /**
     * 取消按钮ID
     */
    public static final int ID_DIALOG_BUTTON_CANCEL = R.id.dialog_messagebox_txtCancel;

    @ViewInject(R.id.dialog_messagebox_txtContent)private TextView txtContent;//消息内容
    @ViewInject(R.id.dialog_messagebox_txtCancel)public TextView txtCancel;//取消
    @ViewInject(R.id.dialog_messagebox_txtOk)public TextView txtOk;//确定
    @ViewInject(R.id.dialog_messagebox_imgClose)private ImageView imgClose;//关闭操作按钮

    public MessageBox(Context context) {
        super(context,R.style.WindowDialogTheme);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View rootView = View.inflate(context, R.layout.dialog_message_box, null);
        setContentView(rootView);
        ViewUtils.inject(this, rootView);
    }

    /**
     * 设置消息内容和按钮文字
     * @param message
     * @param okButtonText
     * @param cancelButtonText
     */
    public void setMessage(String message,String okButtonText,String cancelButtonText){
        txtContent.setText(message);
        txtOk.setText(okButtonText);
        txtCancel.setText(cancelButtonText);
    }

    /**
     * 设置关闭操作可见性,并设置其点击事件
     */
    public void setCloseVisiable(View.OnClickListener listener){
        imgClose.setVisibility(View.VISIBLE);
        imgClose.setOnClickListener(listener);
    }

    /**
     * 设置消息内容
     * @param message
     */
    public void setMessage(String message){
        txtContent.setText(message);
    }

    public void onPositiveNegitiveClick(View.OnClickListener listener){
        if(listener!=null){
            txtCancel.setOnClickListener(listener);
            txtOk.setOnClickListener(listener);
        }
    }

}
